#include <iostream>
using namespace std;
#include <queue>
#include <string>

class Solution 
{
public:
    long long smallestNumber(long long num)
    {
        if (num == 0) return 0;
        char flag = '+';
        if (num < 0) flag = '-', num = -num;
        vector<long long> nums;
        while (num)
        {
            nums.push_back(num % 10);
            num /= 10;
        }

        if (flag == '-')
        {
            priority_queue<long long> heap(nums.begin(), nums.end());
            string ret;
            while (heap.size())
            {
                ret += to_string(heap.top());
                heap.pop();
            }
            return -stoll(ret);
        }
        else
        {
            priority_queue<long long, vector<long long>, greater<long long>> heap(nums.begin(), nums.end());
            string ret;
            long long cnt = 0;
            while (heap.size() && heap.top() == 0)
            {
                cnt++;
                heap.pop();
            }

            ret += to_string(heap.top());
            heap.pop();

            while (cnt--) heap.push(0);

            while (heap.size())
            {
                ret += to_string(heap.top());
                heap.pop();
            }

            return stoll(ret);
        }
    }
};


int main()
{
    cout << Solution().smallestNumber(310);
    return 0;
}